<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教师请假列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>请假教师：</label>
                                <input type="text" name="params[leaverName]" placeholder="输入教师姓名"/>
                            </li>
                            <li>
                                请假类型：<select name="type" th:with="type=${@dict.getType('manage_leave_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li class="select-time">
                                <label style="width: auto;">请假开始时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="leave:leaveTea:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="leave:leaveTea:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info multiple disabled" onclick="$.operate.approveAll('1','通过')" shiro:hasPermission="leave:leaveTea:edit">
                    <i class="fa fa-briefcase"></i> 通过
                </a>
                <a class="btn btn-warning multiple disabled" onclick="$.operate.approveAll('2','拒绝')" shiro:hasPermission="leave:leaveTea:edit">
                    <i class="fa fa-exclamation-triangle"></i> 拒绝
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="leave:leaveTea:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('leave:leaveTea:edit')}]];
        var removeFlag = [[${@permission.hasPermi('leave:leaveTea:remove')}]];
        var typeDatas = [[${@dict.getType('manage_leave_type')}]];
        var prefix = ctx + "leave/leaveTea";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                approveUrl: prefix + "/approve",
                exportUrl: prefix + "/export",
                sortName: 'createTime',
                sortOrder: 'desc',
                modalName: "教师请假",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'leaver',
                    title: '请假教师',
                    formatter: function(value, row, index) {
                        return value.userName;
                    }
                },
                {
                    field: 'type',
                    title: '请假类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'startTime',
                    title: '请假开始时间'
                },
                {
                    field: 'endTime',
                    title: '请假结束时间'
                },
                {
                    field: 'duration',
                    title: '请假时长',
                    formatter: function(value, row, index) {
                        return '<span class="label label-'+(row.durType == 'D'?'primary':'success')+'">'+value+(row.durType == 'D'?'天':'小时')+'</span>';
                    }

                },
                {
                    field: 'status',
                    title: '请假状态',
                    sortable: true,
                    formatter: function(value, row, index) {
                        return '<span class="badge badge-'+(value=='0'?'1':(value == '1'?'info':'danger'))+'">'
                            +(value == '0'?'已申请':(value == '1'?'已通过':'已驳回'))+'</span>';
                    }
                },
                {
                    field: 'status',
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(status != '1') {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.approve(\'' + row.id + '\', \'1\',\'通过\')"><i class="fa fa-briefcase"></i>通过</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.approve(\'' + row.id + '\', \'2\',\'拒绝\')"><i class="fa fa-exclamation-triangle"></i>拒绝</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });
        /*function approve(id) {
            table.set();
            $.modal.confirm("确定通过该请假单吗？", function() {
                var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
                if (table.options.type == table_type.bootstrapTreeTable) {
                    $.operate.get(url);
                } else {
                    var data = { "ids": id };
                    $.operate.submit(url, "post", "json", data);
                }
            });
        }
        function refuse(id) {
            $.modal.open('审批请假单', prefix + "/approveForm", '500', '320', approCallback);
        }
        function approCallback(index, layero) {
            var status = $.modal.getChildFrame(index).find('input[name="optionsRadios"]:checked').val();

            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
                var url = table.options.removeUrl;
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });

            $.operate.submit(url, "post", "json", {"ids":[]});
        }*/
    </script>
</body>
</html>